<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>提货点管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span class="separator"></span>
            <span>提货点名称、电话或地址:</span>
            <input id="keyName" name="keyName" class="mini-textbox" style="width: 300px" emptyText="提货点名称、电话或地址" required="false" requiredErrorText="提货点名称、电话或地址不能为空"/>

            <span>提货点类型:</span>
            <input id="keyPickUpTypeId" name="keyPickUpTypeId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                   required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择提货点类型"/>

            <span>目的站:</span>
            <input id="keyCityId" name="keyCityId" class="mini-treeselect"
                   url="" multiSelect="false" valueField="id" textField="name"  virtualScroll="true"
                   parentField="pid" allowInput="true" valueFromSelect="true"
                   style="width: 250px;" expandOnLoad="0" required="false" nullItemText="请选择..." />

            <div style="margin-top: 5px"></div>
            <% if(so.hasPermission("xtPickUpPoint:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <% if(so.hasPermission("xtPickUpPoint:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>


            <span class="separator"></span>
            <% if(so.hasPermission("xtPickUpPoint:add")){%>
                <a class="mini-button" iconCls="icon-add" onclick="addPickUpPoint('add')">新增</a>
            <% } %>

            <% if(so.hasPermission("xtPickUpPoint:edit")){%>
                <a class="mini-button" iconCls="icon-add" onclick="editPickUpPoint('edit')">编辑</a>
            <% } %>

            <% if(so.hasPermission("xtPickUpPoint:delete")){%>
                <a class="mini-button" iconCls="icon-no" onclick="deletePickUpPoint()">删除</a>
            <% } %>

            <span class="separator"></span>
            <% if(so.hasPermission("xtPickUpPoint:download")){%>
                <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="提货点列表"/>
            <% } %>

        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/basic_data_manage/xt_pick_up_point/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true"
             multiSelect = "true"
             sortField="createTime"
             sortOrder="desc" >
            <div property="columns">
                <div type="checkcolumn" ></div>
                <div field="pickUpTypeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">提货点类型</div>
                <div field="cityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的站</div>
                <div field="name" width="140" headerAlign="center" align="center" allowSort="true">提货点名称</div>
                <div field="phone" width="140" headerAlign="center" align="center" allowSort="true">提货点电话</div>
                <div field="address" width="140" headerAlign="center" align="center" allowSort="true">提货点地址</div>
                <div field="contact" width="140" headerAlign="center" align="center" allowSort="true">联系人</div>
                <div field="contactPhone" width="140" headerAlign="center" align="center" allowSort="true">联系人电话</div>
                <div field="fileId" width="140" headerAlign="center" align="center" allowSort="true" renderer="fileDownRenderer">文件下载</div>
                <div field="cwContactName" width="140" headerAlign="center" align="center" allowSort="true">财务联系人</div>
                <div field="cwContactPhone" width="140" headerAlign="center" align="center" allowSort="true">财务联系人电话</div>
                <div field="comment" width="140" headerAlign="center" align="center" allowSort="true">备注</div>
                <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>
            </div>
        </div>
    </div>

    <!--编辑窗口-->
    <div id="addOrUpdatePanel" class="mini-window" title="提货点管理" style="width:800px;height:400px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  class="mini-button" iconCls="icon-ok" onclick="save()">保存</a>
            <a  class="mini-button" iconCls="icon-close" onclick="closePanel('addOrUpdatePanel')">关闭</a>
        </div>
        <div id="pickUpPointForm">
            <input id="opFlag" name="opFlag" emptyText="操作标志"  class="mini-hidden" required="false" enabled="false" enabled="false" requiredErrorText="操作标志不能为空" />
            <input id="id" name="id" emptyText="id值"  class="mini-hidden" required="false" enabled="false" enabled="false" requiredErrorText="ID不能为空" />

            <span>提货点类型:</span>
            <input id="pickUpTypeId" name="pickUpTypeId" class="mini-combobox" style="width:200px;" textField="name" valueField="id" emptyText="请选择..."
                   required="true" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText=""/>
            <span>目的站:</span>
            <input id="cityId" name="cityId" class="mini-treeselect"
                   url="" multiSelect="false" valueField="id" textField="name"
                   parentField="pid" allowInput="true" valueFromSelect="true"
                   style="width: 250px;" expandOnLoad="0" required="true" nullItemText="请选择..." />
            <div style="margin-top: 5px"></div>
            <span>提货点名称:</span>
            <input id="name" name="name" class="mini-textbox" style="width: 200px" emptyText="提货点名称" required="true" requiredErrorText="提货点名称不能为空"/>
            <span>提货点电话:</span>
            <input id="phone" name="phone" class="mini-textbox" style="width: 100px" emptyText="提货点电话" required="true" requiredErrorText="提货点电话不能为空"/>

            <span>提货点地址:</span>
            <input id="address" name="address" class="mini-textbox" style="width: 200px" emptyText="提货点地址" required="true" requiredErrorText="提货点地址不能为空"/>

            <div style="margin-top: 5px"></div>
            <span>联系人:</span>
            <input id="contact" name="contact" class="mini-textbox" style="width: 200px" emptyText="联系人" required="false" requiredErrorText="联系人不能为空"/>

            <span>联系人电话:</span>
            <input id="contactPhone" name="contactPhone" class="mini-textbox" style="width: 200px" emptyText="联系人电话" required="false" requiredErrorText="联系人电话不能为空"/>

            <div style="margin-top: 5px"></div>
            <span>财务联系人:</span>
            <input id="cwContactName" name="cwContactName" class="mini-textbox" style="width: 200px" emptyText="财务联系人" required="false" requiredErrorText="财务联系人不能为空"/>

            <span>财务联系人电话:</span>
            <input id="cwContactPhone" name="cwContactPhone" class="mini-textbox" style="width: 200px" emptyText="联系人电话" required="false" requiredErrorText="联系人电话不能为空"/>

            <div style="margin-top: 5px"></div>
            <span>备注:</span><textarea id="comment" name="comment" class="mini-textarea" style="width: 80%;height: 50px" emptyText="备注"  required="false"></textarea>

            <div style="margin-top: 5px;display: flex;align-items: center">
                <span>文件附件:</span>
                <input id="fileId" name="fileId" class="mini-hidden" required="true"/>
                <form id="fileUploadForm" style="display: inline">
                    <input type="file" id="upLoadFileData" name="upLoadFileData" />
                </form>
                <a class="mini-button" iconCls="icon-upload" onclick="uploadFile()">上传附件</a>
            </div>


        </div>
    </div>
    <script type="text/javascript">
        mini.parse();

        let keyCityId = mini.get("keyCityId");
        let keyName = mini.get("keyName");
        let keyPickUpTypeId = mini.get("keyPickUpTypeId");

        let grid = mini.get("datagrid1");

        let addOrUpdatePanel = mini.get("addOrUpdatePanel");
        let pickUpPointForm = new mini.Form("#pickUpPointForm");

        let opFlag = mini.get("opFlag");
        let pickUpTypeId = mini.get("pickUpTypeId");
        let cityId = mini.get("cityId");
        let name = mini.get("name");
        let phone = mini.get("phone");
        let address = mini.get("address");
        let contact = mini.get("contact");
        let contactPhone = mini.get("contactPhone");
        let cwContactName = mini.get("cwContactName");
        let cwContactPhone = mini.get("cwContactPhone");
        let comment = mini.get("comment");
        let fileId = mini.get("fileId");


        $(function () {

            // 加载弹出窗口的有效性下拉列表  city
            let keyCityIdJsonData = commonRenderDropList("city");
            keyCityId.loadList(keyCityIdJsonData, "id", "pid");
            cityId.loadList(public_deepClone(keyCityIdJsonData), "id", "pid");

            // 提货点类型
            let pickUpTypeIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_PICK_UP_TYPE");
            keyPickUpTypeId.load(pickUpTypeIdJsonData);
            pickUpTypeId.load(public_deepClone(pickUpTypeIdJsonData));

            // 加载列表数据
            grid.load();

        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch(){
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        /**
         * 文件下载链接生成
         */
        function fileDownRenderer(e) {
            let fileId = e.record.fileId;
            if(public_isEmpty(fileId)){
                return;
            }
            let htmlStr = '<a  class="mini-button"  style="padding: 2px" onclick="downLoadFile(\'' + fileId + '\')">下载</a>';
           return htmlStr;
        }

        /**
         * 根据fileid进文件下载
         */
        function downLoadFile(fileId) {

            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_upload_file/download",{id:fileId});
            if(!ret.ok){
                showAlert(ret.message);
                return;
            }

            // 发送下载请求
            window.location.href="${base}/pages/basic_data_manage/xt_upload_file/filedownload?fileName=" + ret.data;
        }


        function closePanel(panelId) {
            public_onCancel(panelId);
            // 清空数据
            let fileForm = new mini.Form("#fileUploadForm");
            fileForm.clear();

            pickUpPointForm.clear();
        }


        function addPickUpPoint(opFlagValue){
            opFlag.setValue(opFlagValue);
            // 弹出添加窗口
            public_showModelAtPos("addOrUpdatePanel", "center", "middle");
        }


        function editPickUpPoint(opFlagValue){

            let selectItems = grid.getSelecteds();
            if(selectItems.length == 0){
                showAlert("请选择要编辑的提货对象!");
                return;
            }
            if(selectItems.length>1){
                showAlert("请选择一个提货点对象!");
                return;
            }

            pickUpPointForm.setData(selectItems[0]);

            opFlag.setValue(opFlagValue);
            // 弹出添加窗口
            public_showModelAtPos("addOrUpdatePanel", "center", "middle");
        }

        /**
         * 提货点保存
         */
        function save(){

            pickUpPointForm.validate();
            if (pickUpPointForm.isValid() == false) {
                return;
            }

            let data = pickUpPointForm.getData(true);

            mini.confirm("确定保存提货货点信息？", "提货点保存提示",
                function(action) {
                    if (action == "ok") {
                        let  msgBoxId = mini.loading("正在保存，请稍后...","提货点保存提示");
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_pick_up_point/save",data);
                        mini.hideMessageBox(msgBoxId);
                        showAlert(ret.message,function (){
                            if(ret.ok){
                                // 重新刷新数据
                                grid.reload();
                                closePanel('addOrUpdatePanel');

                                // 清空上传对象
                                clearUploadFile("fileUploadForm");

                                // 刷新缓存
                                refreshCache();
                            }
                        });
                    }
                });
        }

        function uploadFile(){
            let fileInput = $('#upLoadFileData').get(0).files[0];
            if(fileInput){
                mini.confirm("确认上传提货点附件?", "上传提示", function(confirmAction){
                    if(confirmAction == "ok"){
                        ajaxFileUpload();
                    }
                });
            }else{
                mini.alert("没有选择要上传的航班信息数据Excel文件!");
            }
        }

        /**
         * 上传文件  413475243524771841
         */
        function ajaxFileUpload(){
            let  msgBoxId = mini.loading("正在上传校验及上传处理中，请稍后...","文件上传");
            let formData = new FormData($("#fileUploadForm")[0]);
            $.ajax({
                //接口地址
                url: '${base}/pages/basic_data_manage/xt_upload_file/upload',
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (res) {
                    if(res.ok){
                        mini.hideMessageBox(msgBoxId);
                        fileId.setValue(res.data);
                    }
                    showAlert(res.message);
                },
                error: function (res) {
                    mini.hideMessageBox(msgBoxId);
                    mini.alert("网络异常，请重试！");
                }
            });
        }


        function deletePickUpPoint(){
            let selectItems = grid.getSelecteds();
            if(selectItems.length == 0){
                showAlert("请选择要删除的提货对象对象!");
                return;
            }

            let ids = "";
            for(let obj of selectItems){
                ids += "'" + obj.id + "',";
            }

            ids = ids.substring(0,ids.length - 1);

            if(ids.length>0){
                mini.confirm("确定删除选择的提货货点？", "提货点删除提示",
                    function(action) {
                        if (action == "ok") {
                            let  msgBoxId = mini.loading("正在删除，请稍后...","提货点删除提示");
                            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_pick_up_point/delete?ids="+ids);
                            mini.hideMessageBox(msgBoxId);
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    // 重新刷新数据
                                    grid.reload();
                                    // 刷新缓存
                                    refreshCache();
                                }
                            });
                        }
                    });
            }
        }

        // 刷新缓存，把刷新的缓存放到父页面，应当调用父级页面方法刷新
        function refreshCache() {
            parent.window.loadCache();
        }


    </script>
</body>
</html>